package entities;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.*;

import ejb.dto.ReservationDTO;


/**
 * The persistent class for the reservations database table.
 * 
 */
@Entity
@Table(name="reservations", uniqueConstraints={
		@UniqueConstraint(columnNames={"USER_ID", "DATE_RESERVATION"})
})
@NamedQuery(name="Reservation.findAll", query="SELECT r FROM Reservation r ORDER BY r.dateReservation DESC")
public class Reservation implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;

	@Temporal(javax.persistence.TemporalType.TIMESTAMP)
	@Column(name="DATE_RESERVATION")
	private Date dateReservation;
	
	@ManyToOne
	@JoinColumn(name="EXCURSION_DATES")
	private ExcursionAvailability excursionDates;

	@ManyToOne
	@JoinColumn(name="HOTEL_DATES")
	private HotelAvailability hotelDates;

	private float price;
	
	@Column(name="PEOPLE_NUMBER")
	private int peopleNumber;

	/**
	 * bi-directional many-to-one association to Package
	 */
	@ManyToOne
	@JoinColumn(name="PACKAGE_ID")
	private Package pack;

	/**
	 * bi-directional many-to-one association to Flight
	 */
	@ManyToOne
	@JoinColumn(name="OUTBOUND_FLIGHT")
	private Flight flight1;

	/**
	 * bi-directional many-to-one association to Flight
	 */
	@ManyToOne
	@JoinColumn(name="RETURN_FLIGHT")
	private Flight flight2;
	
	/**
	 * bi-directional many-to-one association to User
	 */
	@ManyToOne
	@JoinColumn(name="USER_ID")
	private User user;

	
	//CONSTRUCTORS
	public Reservation() {
	}
	
	public Reservation(ReservationDTO reservation, entities.Package pack, HotelAvailability ha, ExcursionAvailability ea, Flight flight1, Flight flight2, User user){
		this.pack = pack; 
		this.hotelDates = ha;
		this.excursionDates = ea;
		this.flight1 = flight1;
		this.flight2 = flight2;
		this.price = reservation.getTotalPrice();
		this.setPeopleNumber(reservation.getPeopleNumber());
		this.dateReservation = new Date();
		this.user = user;
	}

	
	
	//GETTER AND SETTER
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Date getDateReservation() {
		return this.dateReservation;
	}

	public void setDateReservation(Date dateReservation) {
		this.dateReservation = dateReservation;
	}



	public float getPrice() {
		return this.price;
	}

	public void setPrice(float price) {
		this.price = price;
	}

	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Package getPackage() {
		return this.pack;
	}

	public void setPackage(Package pack) {
		this.pack = pack;
	}

	public Flight getFlight1() {
		return this.flight1;
	}

	public void setFlight1(Flight flight1) {
		this.flight1 = flight1;
	}

	public Flight getFlight2() {
		return this.flight2;
	}

	public void setFlight2(Flight flight2) {
		this.flight2 = flight2;
	}

	public int getPeopleNumber() {
		return peopleNumber;
	}

	public void setPeopleNumber(int peopleNumber) {
		this.peopleNumber = peopleNumber;
	}
	
	public ExcursionAvailability getExcursionDates() {
		return excursionDates;
	}

	public void setExcursionDates(ExcursionAvailability excursionDates) {
		this.excursionDates = excursionDates;
	}

	public HotelAvailability getHotelDates() {
		return hotelDates;
	}

	public void setHotelDates(HotelAvailability hotelDates) {
		this.hotelDates = hotelDates;
	}


}